#include <bwio.h>
#include <user.h>
#include <ts7200.h>
#include <uart.h>
#include <io.h>
#include <defs.h>

void NameServer();
void TerminalRxServer();
void TerminalTxServer();
void ClockServer();
void TrainTxServer();
void TrainRxServer();
void IdleTask();

void UserInit() {
  int child;
  bwprintf(COM2, "BEFORE NameServer\r\n");
  child = Create( 8, &NameServer );
  Send(child, NULL, 0, NULL, 0);
  bwprintf(COM2, "BEFORE TerminalTxServer\r\n");
  child = Create( 8, &TerminalTxServer );
  Send(child, NULL, 0, NULL, 0);
  bwprintf(COM2, "BEFORE ClockServer\r\n");
  child = Create( 8, &ClockServer );
  Send(child, NULL, 0, NULL, 0);
  bwprintf(COM2, "BEFORE TrainTxServer\r\n");
  child = Create( 8, &TrainTxServer );
  Send(child, NULL, 0, NULL, 0);
  bwprintf(COM2, "BEFORE TerminalRxServer\r\n");
  child = Create( 8, &TerminalRxServer );
  Send(child, NULL, 0, NULL, 0);
  bwprintf(COM2, "BEFORE TrainRxServer\r\n");
  child = Create( 8, &TrainRxServer );
  Send(child, NULL, 0, NULL, 0);
  bwprintf(COM2, "BEFORE IdleTask\r\n");
  Create( 0, &IdleTask );
  char c;
   /*
  for (c = 'a'; c <= 'z'; c++) {
    Putc( COM2, c ); 
  }
  Putc( COM2, '\r' ); 
  Putc( COM2, '\n' ); 
  
 
  Printf(COM1, "Hello, this is your printf speakingHello, this is your printf speakingHello");
*/
 /*
   int i;
  for (i = 0; i < 3; i++) {
    c = Getc( COM2 );
    Putc( COM2, c );
  }
  */
  
  // Printf(COM2, "After Getc\r\n");
  /* S
  int j;
  for (j = 0; j < 1; j++) {
    
    //int i;
    //for (i = 0; i < 2000000; i++);
  }
  */
  /*
  int j;
  for (j = 5; j < 9; j++) {
    Putc(COM1, 33);
    Putc(COM1, j);
  }
  for (j = 5; j < 9; j++) {
    Putc(COM1, 34);
    Putc(COM1, j);
  }
  int i;
  
    Putc(COM1, 10);
    Putc(COM1, 9);
    
  
  for (i = 0; i < 2000000; i++);
  
  for (j = 0; j < 1; j++) {
    Putc(COM1, 0);
    Putc(COM1, 9);
    
    Putc(COM1, 15);
    Putc(COM1, 9);
    
    Putc(COM1, 10);
    Putc(COM1, 9);
    
    for (i = 0; i < 2000000; i++);
  }c
  char sensors[10];
	Putc(COM1, 133); 
	// bwprintf(COM2, "Getting...");
	for (i = 0; i < 10; i++) 
	{			
		bwprintf(COM2, "Get: %d\r\n", Getc(COM1));
	}
	*/
	/*
	bwprintf(COM1, "Program\r\n");
	Printf("Hi my name, hi, my name is, hi, m\r\ny name is chiki-chiki Slim Shady! Hi my name, hi, my name is sH\r\ni my name, hi, my name is, hi, my name is chiki-chiki\r\n Slim Shady! Hi my name, hi, my name is\r\n s,Hi my name, hi, my name is, hi, my name is chiki-chik\r\ni Slim Shady! Hi my name, hi, my name is s,Hi \r\nmy name, hi, my name is, hi, my name is c\r\nhiki-chiki Slim Shady! Hi my name, hi, \r\nmy name is s,Hi my name, hi, my name is, hi, \r\nmy name is chiki-chiki Slim Shady! Hi my na\r\nme, hi, my name is s,Hi my name, hi,\r\n my name is, hi, my name is chiki-chiki Slim \r\nShady! Hi my name, hi, my name is s,, hi, \r\nmy name is chiki-chiki Slim Shady!\r\n");
	Printf("\r\n\r\n");
	Printf("Hi my name is %s, I'm %d years old,\r\nmy favourite number is 0x%x and %c", "Ondrej", 23, 0xdeadbeef, '$');
	*/
	bwprintf(COM2, "Time 0: %d\r\n", Time());
  int i;
	for (i = 0; i < 1000000; i++) ;
	bwprintf(COM2, "Time 1: %d\r\n", Time());
	
  Exit();
}
